package com.zzg.srb.core.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzg.srb.common.result.R;
import com.zzg.srb.core.entity.pojo.Borrower;
import com.zzg.srb.core.entity.pojo.BorrowerAttach;
import com.zzg.srb.core.entity.vo.BorrowerApprovalVo;
import com.zzg.srb.core.entity.vo.BorrowerAttachVo;
import com.zzg.srb.core.entity.vo.BorrowerDetailVo;
import com.zzg.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @Author zhengzg
 * @Date 2022/8/15 11:24
 * @Version 1.0
 */
@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    private Logger log = LoggerFactory.getLogger(AdminBorrowerController.class);

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前页码", required = true),
            @ApiImplicitParam(value = "每页记录数", required = true),
            @ApiImplicitParam(value = "查询关键字", required = false)
    })
    public R listPage(@PathVariable Long page, @PathVariable Long limit, @RequestParam String keyword) {
        log.info("获取借款人分页列表 ==============》 AdminBorrowerController。listPage: " + keyword);
        Page<Borrower> pageParam = new Page<>(page, limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);
        return R.ok().data(pageModel);
    }

    @ApiOperation("获取借款人信息")
    @ApiImplicitParam(value = "借款人id",required = true)
    @GetMapping("/show/{id}")
    public R show(@PathVariable Long id){
        log.info("获取借款人信息 ===========> AdminBorrowerController.show: " +id );
        BorrowerDetailVo borrowerDetailVo = borrowerService.getBorrowerDetailVoById(id);
        return R.ok().data(borrowerDetailVo);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVo borrowerApprovalVo){
        log.info("借款额度审批 ===================> AdminBorrowerController.approval: " + borrowerApprovalVo);
        borrowerService.approval(borrowerApprovalVo);
        return R.ok().message("审批完成");
    }
}